//
//  HEReportInputCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/18.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEReportInputCell.h"

@interface HEReportInputCell ()<QMUITextFieldDelegate>

@property(nonatomic, strong) QMUITextField *inputTF;

@end
 
@implementation HEReportInputCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    _inputTF = [[QMUITextField alloc] init];
    _inputTF.delegate = self;
    _inputTF.backgroundColor = [UIColor qmui_colorWithHexString:@"F1F3F8"];
    _inputTF.placeholder = @"请输入";
    _inputTF.font = DYFont(15);
    _inputTF.layer.cornerRadius = 4;
    _inputTF.textInsets = UIEdgeInsetsMake(0, 10, 0, 10);
    _inputTF.clearButtonMode = UITextFieldViewModeAlways;
    [self.contentView addSubview:_inputTF];
    
    [_inputTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(15);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.height.mas_offset(35);
        make.bottom.equalTo(self.contentView).mas_offset(-0);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    
    _inputTF.placeholder = fiterModel.placeHolder;
    _inputTF.text = formModel.rp_title;
    _inputTF.enabled = fiterModel.enable;

    _inputTF.text = [formModel valueForKey:fiterModel.tableKey];
}

#pragma mark - TextFiledDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString *text = [textField.text stringByReplacingCharactersInRange:range withString:string];
    [self.formModel setValue:text forKey:self.fiterModel.tableKey]; //  值赋给_formModel
    return YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
